package cn.school.sys.vo.export.convert;

import cn.school.sys.entity.SysRole;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.List;

public class SysRoleLIstConvert implements Converter<List<SysRole>> {
    @Override
    public Class supportJavaTypeKey() {
        return null;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public List<SysRole> convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public CellData convertToExcelData(List<SysRole> roles, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        StringBuffer roleNames = new StringBuffer();
        CellData cellData = null;
        if (roles!=null && roles.size()!=0) {

            for (SysRole sysRole : roles) {
                roleNames.append(sysRole.getName()).append(",");
            }
            if(roleNames.length()!=0) {
                cellData = new CellData(roleNames.substring(0, roleNames.length()-1));
            }
        }
        return cellData;
    }
}
